package com.fancy.application.sys.log.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fancy.application.common.controller.BaseController;
import com.fancy.application.common.vo.BasePage;
import com.fancy.application.common.vo.Result;
import com.fancy.application.sys.log.entity.SysLogLoginMain;
import com.fancy.application.sys.log.service.ISysLogLoginMainService;
import com.fancy.application.sys.log.vo.SysLogLoginMainVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* fancycode自动生成v1.0
* @author wison
* 2020-01-02
*/

@RestController
@RequestMapping("/sys/log/sys_log_login_main")
public class SysLogLoginMainController extends BaseController {
@Resource
private ISysLogLoginMainService baseService;

    @PostMapping(value = "/list")
    public Result list(@RequestBody BasePage<SysLogLoginMain> basePage){
        IPage<SysLogLoginMain> sysLogLoginMainPage = baseService.page(basePage.getPage(),basePage.getWrapper("fd_login_name").orderByDesc("fd_create_time"));
        return Result.ok(sysLogLoginMainPage);
    }

    @PutMapping
    public Result save(@RequestBody SysLogLoginMainVo sysLogLoginMainVo){
        SysLogLoginMain sysLogLoginMain = new SysLogLoginMain();
        BeanUtil.copyProperties(sysLogLoginMainVo,sysLogLoginMain,CopyOptions.create().ignoreNullValue());
        baseService.saveOrUpdate(sysLogLoginMain);
        return Result.ok();
    }
    @DeleteMapping
    public Result del(@RequestParam(required = false) String id ){
        baseService.removeById(id);
        return Result.ok();
    }
    @GetMapping
    public Result view(@RequestParam(required = false) String id ){
        SysLogLoginMainVo sysLogLoginMainVo = new SysLogLoginMainVo();
        SysLogLoginMain sysLogLoginMain = baseService.getById(id);
        BeanUtil.copyProperties(sysLogLoginMain,sysLogLoginMainVo,CopyOptions.create().ignoreNullValue());
        return Result.ok().addData(sysLogLoginMainVo);
    }
    @PostMapping(value = "/clearAllLog")
    public Result clearAllLog(){
        this.baseService.removeAllLog();
        return Result.ok();
    }
}
